{extend name="common:base" /}

{block name="main"}
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">商品列表</strong> / <small>Goods List</small></div>
    </div>
    <hr>
    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <select name="filter" data-am-selected="{btnSize: 'sm'}">
                    <option value="all">显示所有商品</option>
                    <option value="1">在售</option>
                    <option value="2">已售出</option>
                    <option value="3">卖家下架</option>
                    <option value="4">超时下架</option>
                    <option value="5">待审核</option>
                    <option value="-1">审核未通过</option>
                    <option value="0">已删除</option>
                </select>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-input-group am-input-group-sm">
                <input id="ser_input" type="text" class="am-form-field" onkeydown="EnterPress()">
                <span class="am-input-group-btn">
                    <button id="ser_button" class="am-btn am-btn-default" type="button">搜索</button>
                </span>
            </div>
        </div>
    </div>
    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                        <tr>
                            <th class="table-check">
                                <input type="checkbox" id="che"/>
                            </th>
                            <th class="table-id">ID</th>
                            <th class="table-title">商品名</th>
                            <th class="table-type">商品类型</th>
                            <th class="table-author">用户名</th>
                            <th class="table-status">商品当前状态</th>
                            <th class="table-set">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    {volist name="list" id="vo"}
                        <tr>
                            <td class="list-check">
                                <input type="checkbox" name="ches"/>
                            </td>
                            <td>{$vo.good_id}</td>
                            <td><a href="{:url('goods/detail',['good_id'=>$vo.good_id])}">{$vo.title}</a></td>
                            <td>{$vo.cate_id|get_goodtype}</td>
                            <td>{$vo.user_id|get_username}</td>
                            <td>{$vo.status}</td>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        {if ($vo.status == "待审核" || $vo.status == "审核未通过")}
                                            <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="ajax_through({$vo.good_id})" type="button"><span class="am-icon-pencil-square-o"></span>
                                            通过审核
                                            </button>
                                        {else/}
                                            <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="ajax_through({$vo.good_id})" disabled type="button"><span class="am-icon-pencil-square-o"></span>
                                            无法操作
                                            </button>
                                        {/if}

                                        {if ($vo.status == "待审核" || $vo.status == "在售")}
                                            <button class="am-btn am-btn-default am-btn-xs am-hide-sm-only" onclick="ajax_nothrough({$vo.good_id})" type="button"><span class="am-icon-copy"></span>
                                            不予通过审核
                                            </button>
                                        {else/}
                                            <button class="am-btn am-btn-default am-btn-xs am-hide-sm-only" onclick="ajax_nothrough({$vo.good_id})" disabled type="button"><span class="am-icon-copy"></span>
                                            无法操作
                                            </button>
                                        {/if}

                                        {if ($vo.status == "已售出" || $vo.status == "卖家下架" || $vo.status == "超时下架")}
                                            <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="ajax_recycle({$vo.good_id})" disabled type="button"><span class="am-icon-trash-o"></span>
                                            无法操作
                                            </button>
                                        {elseif $vo.status == "已删除"/}
                                            <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="ajax_recycle({$vo.good_id})" type="button"><span class="am-icon-trash-o"></span>
                                            取消删除
                                            </button>
                                        {else/}
                                            <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="ajax_recycle({$vo.good_id})" type="button"><span class="am-icon-trash-o"></span>
                                            删除
                                            </button>
                                        {/if}

                                    </div>
                                </div>
                            </td>
                        </tr>
                    {/volist}
                    </tbody>
                </table>
                    <div class="am-cf">
                        <div class="am-cf">
                        {$list->render()}
                    </div>
                </div>
                <hr />
  <p><pre>
  注：本页使用方法：
          1、搜索框的功能默认使用商品名搜索，若要以用户名为参数进行搜索，需在后面添加一个英文逗号。
          2、选择框的作用是批量展示同一状态的商品。
          3、还可以利用搜索框和选择框进行连贯操作，比如先通过搜索框搜索用户名为“苦丁茶”的用户的全部商品，
             然后再通过选择框选择该用户下处于不同状态的商品。
          4、在操作里面有三个选项，分别为通过审核，不予通过审核，以及删除。
  <pre></p>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
$('select[name="filter"]').find('option[value="{:input('param.filter', '')}"]').attr('selected', true);
if (!$.AMUI.support.mutationobserver) {
    $selected.trigger('changed.selected.amui');
}
$('select[name="filter"]').on('change', function(event) {
    var el = $(this).val();
    var s = window.location.pathname.split("/");
    var len = s.length;
    if (s[len-2] == "title") {
        var title = s[len-1];
        if (el != "all") {
        location.href = "{:url('admin/goods/list')}/filter/"+ el + "/title/" + title;
        }
        else {
            location.href = "{:url('admin/goods/list')}/filter/"+ el;
        }
    }
    else {
        location.href = "{:url('admin/goods/list')}/filter/"+ el;
    }
});
function ajax_recycle(good_id) {
    $.get("{:url('admin/goods/recycle')}?good_id=" + good_id, function(result) {
        if (result == true) {
            alert("修改成功！");
            location.reload(true);
        }
        else
            alert("修改失败！");
    });
}
function ajax_through(good_id) {
    $.get("{:url('admin/goods/through')}?good_id=" + good_id, function(result) {
        if (result == true) {
            alert("修改成功！");
            location.reload(true);
        }
        else
            alert("修改失败！");
    });
}
function ajax_nothrough(good_id) {
    $.get("{:url('admin/goods/nothrough')}?good_id=" + good_id, function(result) {
        if (result == true) {
            alert("修改成功！");
            location.reload(true);
        }
        else
            alert("修改失败！");
    });
}
function EnterPress() { //传入 event
    var e = window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode == 13 ) {
        var title = $('#ser_input').val();
        if (title != ""){
            location.href = "{:url('admin/goods/list')}/title/"+ title;
        }
    }
}
$('#ser_button').on('click', function() {
    var title = $('#ser_input').val();
    if (title != ""){
        location.href = "{:url('admin/goods/list')}/title/"+ title;
    }
});
</script>
{/block}
